package com.codeest.geeknews.util.notify;

import android.app.PendingIntent;
import android.content.Context;
import android.graphics.BitmapFactory;
import android.support.v4.app.NotificationCompat;
import android.widget.RemoteViews;

import com.codeest.geeknews.R;

/**
 * </br>
 * NotificationCompat.Builder builder = new NotificationCompat.Builder(context);<br>
 * //状态栏文字<br>
 * builder.setTicker(ticker);<br>
 * //通知栏标题<br>
 * builder.setContentTitle(title);<br>
 * //通知栏内容<br>
 * builder.setContentText(content);<br>
 * //触发的intent<br>
 * builder.setContentIntent(intent);<br>
 * //这边设置颜色，可以给5.0及以上版本smallIcon设置背景色<br>
 * builder.setColor(Color.RED);<br>
 * //小图标<br>
 * builder.setSmallIcon(smallIcon);<br>
 * //大图标(这边同时设置了小图标跟大图标，在5.0及以上版本通知栏里面的样式会有所不同)<br>
 * builder.setLargeIcon(BitmapFactory.decodeResource(context.getResources(),R.mipmap.ic_launcher));<br>
 * //设置该条通知时间<br>
 * builder.setWhen(System.currentTimeMillis());<br>
 * //设置为true，点击该条通知会自动删除，false时只能通过滑动来删除<br>
 * builder.setAutoCancel(true);<br>
 * //设置优先级，级别高的排在前面<br>
 * builder.setPriority(NotificationCompat.PRIORITY_MAX);<br>
 * int defaults = 0;<br>
 * if(sound)<br>
 * <p><br>
 * {<br>
 * defaults |= Notification.DEFAULT_SOUND;<br>
 * }<br>
 * if(vibrate)<br>
 * <p><br>
 * {<br>
 * defaults |= Notification.DEFAULT_VIBRATE;<br>
 * }<br>
 * if(lights)<br>
 * <p><br>
 * {<br>
 * defaults |= Notification.DEFAULT_LIGHTS;<br>
 * }<br>
 * //设置声音、闪光、震动<br>
 * builder.setDefaults(defaults);<br>
 * //设置是否为一个正在进行中的通知，这一类型的通知将无法删除<br>
 * builder.setOngoing(true);<br>
 * Created by admin on 2017/7/17.<br>
 */
abstract class NotifyBuilder extends NotificationCompat.Builder implements INotify {


    public NotifyBuilder(Context context) {
        this(context, null);
    }

    public NotifyBuilder(Context context, Object extra) {
        super(context);
        intCustomContentView();
        initTicker();
        initTitle();
        initSmallIcon();
        initLargeIcon();
        initContentIntent();
        initOtherIntent(extra);
    }


    /**
     * 带参数
     * 可以自定义跳转界面、广播、服务
     */
    protected void initOtherIntent(Object obj) {
    }

    private void initTicker() {
        setTicker(ticker());
    }

    private void intCustomContentView() {
        RemoteViews remoteViews = new RemoteViews(mContext.getPackageName(), contentViewLayout());
        setCustomContentView(remoteViews);
    }

    private void initTitle() {
        setContentTitle(title());
    }

    private void initContentIntent() {
        setContentIntent(contentIntent());
    }

    private void initSmallIcon() {
        setSmallIcon(smallIcon());
    }

    private void initLargeIcon() {
        setLargeIcon(BitmapFactory.decodeResource(mContext.getResources(), R.mipmap.ic_launcher));
    }

    @Override
    public String ticker() {
        return "ticker";//Default
    }

    @Override
    public String title() {
        return "title";//Default
    }


    @Override
    public String content() {
        return "content";//Default
    }

    /**
     * 设置小图标
     *
     * @return
     */
    @Override
    public int smallIcon() {
        //BUG:没有notification通知显示。
        //解决:请设置icon
        return R.mipmap.ic_launcher;//Default
    }

    /**
     * 设置布局
     *
     * @return -
     */
    @Override
    public abstract int contentViewLayout();

    /**
     * 设置点击通知栏操作
     *
     * @return
     */
    @Override
    public PendingIntent contentIntent() {
//        // 设置点击通知栏操作
//        Intent in = new Intent(mContext, MainActivity.class);// 点击跳转到指定页面
//        return PendingIntent.getActivity(mContext, 0, in, 0);
        return null;
    }
}
